package com.kefu.call.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.call.model.CallMakeCall;
import com.kefu.call.service.CallMakeCallService;
import com.kefu.call.vo.CallMakeCallVo.*;
import com.kefu.chat.vo.ChatSessionRptVo;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Api(tags = "外呼相关业务")
@RestController
@RequestMapping("call/callMakeCall/")
public class CallMakeCallController extends AbstractBaseController {
    @Resource
    private CallMakeCallService callMakeCallService;

    @PostMapping("callMakeCallRecord")
    @ApiOperation(value = "呼出自定义纪录", notes = "呼出自定义纪录")
    public Result<Page<Map<String, Object>>> callMakeCallRecord(@Validated @RequestBody CallMakeCallRptVo searchVo) {
        return ResultGenerator.genSuccessResult(callMakeCallService.callMakeCallRecord(searchVo));
    }

    @PostMapping("/callMakeCallRecordExport")
    @ApiOperation(value = "导出外呼纪录", notes = "导出外呼纪录")
    public void sessionRecordExport(@Validated @RequestBody CallMakeCallRptVo search, HttpServletResponse response) throws IOException {
        List<Object[]> exportList = callMakeCallService.callMakeCallRecordExport(search);
        csvWriter(exportList, response);
    }
}
